import prizeApi from '../../api/prizeApi'
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    pageNum: 0,
    pageSize: 10,
    list: [],
    isMore: true
  },
  lifetimes: {
    attached: function () {
      this.getList(1)
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show: function () { },
    hide: function () { },
    resize: function () { },
    onPullDownRefresh: function () {
      console.log('price top onPullDownRefresh')
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    async getList(num) {
      if (!this.data.isMore) {
        return
      }
      this.data.pageNum = num
      let res = await prizeApi.getAllPrize({
        pageNum: this.data.pageNum,
        pageSize: this.data.pageSize,
        status: 0,
        open: true
      })
      this.setData({
        list: this.data.list.concat(res),
        isMore: res.length == this.data.pageSize
      })
    },

    async refresh(){
      this.setData({
        list: [],
        isMore: true
      })
      await this.getList(1)
    },

    toDetail(e) {
      let item = e.currentTarget.dataset.item
      
      wx.navigateTo({
        url: '/prize/prizeDetail/prizeDetail?prizeId='+item._id,
      })
    },
  }
})